#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


class Solution {
public:
    vector<vector<int>> fourSum(vector<int>& nums, int target)
    {
        vector<vector<int>> vt;
        sort(nums.begin(), nums.end());
        int n = nums.size();
        for (int i = 0; i < n - 3; i++)
        {

            if (i != 0 && nums[i] == nums[i - 1])
            {
                //i++;
                continue;

            }
            //int sum1=target-nums[i];

            for (int j = i + 1; j < n; j++)
            {
                if (j != i + 1 && nums[j] == nums[j - 1])
                {
                    //j++;
                    continue;

                }

                //int sum2=sum1-nums[j];

                int left = j + 1, right = n - 1;
                while (left < right)
                {
                    if (left < right && left != j + 1 && nums[left] == nums[left - 1])
                    {
                        left++;
                        continue;

                    }

                    if (left < right && right != n - 1 && nums[right] == nums[right + 1])
                    {
                        right--;
                        continue;

                    }

                    long long sum = (long long)target - (long long)nums[i] - (long long)nums[j], count = (long long)nums[left] + (long long)nums[right];

                    if (sum == count)
                        vt.push_back({ nums[i],nums[j],nums[left],nums[right] }), left++, right--;
                    else if (sum > count)
                        left++;
                    else if (sum < count)
                        right--;


                }
            }
        }
        return vt;

    }
};


int main()
{
    vector<int> v({ 1000000000,1000000000,1000000000,1000000000 });
    Solution().fourSum(v, -294967296);


    return 0;
}